package com.ycsj.goldmedalnewconcept.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.bean.ScoreManageResponse.TestTheme;
import com.ycsj.goldmedalnewconcept.view.NineGridView;
import com.ycsj.goldmedalnewconcept.R;

public class ScoreManageAdapter extends BaseAdapter {

	private Context context;
	private List<TestTheme> data = new ArrayList<TestTheme>();
	private LayoutInflater mInflater;

	public void setData(List<TestTheme> data) {
		this.data = data;
		notifyDataSetChanged();
	}

	public ScoreManageAdapter(Context context, List<TestTheme> data
			) {
		this.context = context;
		this.data = data;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public TestTheme getItem(int position) {
		return (TestTheme) data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_testtheme, parent,
					false);
			convertView.setTag(new ViewHolder(convertView));
		}
		final ViewHolder holder = (ViewHolder) convertView.getTag();
		TestTheme item = getItem(position);
		
		holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
		holder.tv_tag = (TextView) convertView.findViewById(R.id.tv_tag);
		
		
		holder.tv_tag.setText(data.get(position).tag);
		holder.tv_time.setText(data.get(position).update_date);
		
		
		return convertView;
	}

	class ViewHolder {
		private TextView tv_tag;
		private TextView tv_time;
		
		
		private View rootView;

		public ViewHolder(View convertView) {
			rootView = convertView;
			NineGridView.setImageLoader(new PicassoImageLoader());
		} 

		/** Picasso 加载 */
		private class PicassoImageLoader implements NineGridView.ImageLoader {

			@Override
			public void onDisplayImage(Context context, ImageView imageView,
					String url) {
				Picasso.with(context).load(url)//
						.placeholder(R.drawable.temp)//
						.error(R.drawable.temp)// 
						.into(imageView);
			}

			@Override
			public Bitmap getCacheImage(String url) {
				
				return null;
			}
		}

	}
}
